#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int N = 200005, M = 1000005;
int n, a[N], las[M], lst[M]; LL f[N][2], sum[N];
int main() {
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    int T; scanf("%d", &T);
    while (T--) {
        scanf("%d", &n);
        for (int i = 1; i <= n; i++)
            scanf("%d", &a[i]), lst[i] = las[a[i]], las[a[i]] = i, sum[i] = sum[i - 1] + (a[i] == a[i - 1] ? a[i] : 0);
        f[0][0] = -INF, f[0][1] = 0;
        for (int i = 1; i <= n; i++) {
            f[i][1] = max(f[i - 1][1], f[i - 1][0] + a[i]);
            if (i < n && lst[i + 1]) {
                if (lst[i + 1] == i) f[i][0] = max(f[i - 1][1], f[i - 1][0] + a[i]);
                else f[i][0] = sum[i] - sum[lst[i + 1] + 1] + max(f[lst[i + 1]][1], f[lst[i + 1]][0] + a[lst[i + 1] + 1]);
            } else f[i][0] = -INF;
        }
        for (int i = 1; i <= n; i++) las[a[i]] = 0, lst[i] = 0;
        printf("%lld\n", f[n][1]);
    }
    return 0;
}